import { Transfer,Form ,Button} from 'antd';
import React from 'react'
import './asso.css'
import {createProduct} from '@/api/pms/productApi.js'
export default class extends React.Component{
	state={
		mockData: [
			{key:'1',title:'polo衬衫也得时尚'},
			{key:'2',title:'大牌手机低价秒'},
			{key:'3',title:'晓龙845新品上市'},
			{key:'4',title:'夏天应该穿什么'},
			{key:'5',title:'夏季精选'},
			{key:'6',title:'品牌手机降价'},
		],
		targetKeys: [],
		mockData2: [
			{key:'a',title:'让音质更出众'},
			{key:'b',title:'让音质更出众2'},
			{key:'c',title:'让音质更出众3'},
			{key:'d',title:'让音质更出众4'},
		],
		targetKeys2: [],
	}
	 getMock = () => {
		let Keys = [this.state.mockData.key];
	    this.setState({targetKeys:Keys});
		let Keys2 = [this.state.mockData2.key]
		this.setState({targetKeys2:Keys2})
	  };
	  filterOption = (inputValue, option) => option.description.indexOf(inputValue) > -1;
	  
	    handleChange = targetKeys => {
	      this.setState({ targetKeys});
	    };
		handleChange2 = targetKeys2 => {
		  this.setState({ targetKeys2 });
		};
	  
	    handleSearch = (dir, value) => {
	      console.log('search:', dir, value);
	    };
	render(){
		const {handleStep,productData} = this.props;
		const onFinish = (values)=>{
			console.log("完成,",productData);
			createProduct(productData)
			.then(data=>{
				if(data.code == 200){
					alert("成功");
				}else{
					alert("添加失败")
				}
			})
		}
		return <Form
			onFinish={onFinish}
		>
			<Form.Item
				style={{marginLeft:'25px'}}
				name="subject"
				label="关联专题"
			>
			  <Transfer
				dataSource={this.state.mockData}
				showSearch
				targetKeys={this.state.targetKeys}
				filterOption={this.filterOption}
				onChange={this.handleChange}
				onSearch={this.handleSearch}
				render={item => item.title}
			  />
			</Form.Item>
			<Form.Item
				style={{marginLeft:'25px'}}
				name="prefer"
				label="关联优选"
			>
			  <Transfer
				dataSource={this.state.mockData2}
				showSearch
				targetKeys={this.state.targetKeys2}
				filterOption={this.filterOption}
				onChange={this.handleChange2}
				onSearch={this.handleSearch}
				render={item => item.title}
			  />
			</Form.Item>
	  <Button type="primary" onClick={handleStep.bind(this,-1)}>上一步,填写商品属性</Button>
	  <Button type="primary" htmlType="submit">完成，提交商品</Button>
	  </Form>
	}
} 